<?php

namespace Dreamcat\PropertyAnalysis\Pojo;

use JetBrains\PhpStorm\Immutable;
use JetBrains\PhpStorm\Pure;
use ReflectionMethod;
use ReflectionProperty;

/**
 * 属性的分析结果
 * @author vijay
 */
class PropertyResult
{
    /** @var null|TypeDescription 类型描述 */
    private ?TypeDescription $typeDescription = null;

    /** @var ?ReflectionMethod setter方法的反射 */
    private ?ReflectionMethod $setter = null;
    /** @var ?TypeDescription setter方法的调用类型描述 */
    private ?TypeDescription $setterTypeDescription = null;
    /** @var bool setter方法与属性是否在同一类 */
    private bool $setterSameClass = true;

    /**
     * @param ReflectionProperty $property 属性反射
     */
    public function __construct(#[Immutable] private ReflectionProperty $property)
    {
    }

    /**
     * @return ReflectionProperty 属性反射
     */
    #[Pure]
    public function getProperty(): ReflectionProperty
    {
        return $this->property;
    }

    /**
     * @return TypeDescription|null 类型描述
     */
    #[Pure]
    public function getTypeDescription(): ?TypeDescription
    {
        return $this->typeDescription;
    }

    /**
     * @param TypeDescription $typeDescription 类型描述
     */
    public function setTypeDescription(TypeDescription $typeDescription): void
    {
        $this->typeDescription = $typeDescription;
    }

    /**
     * @return ReflectionMethod|null
     * @codeCoverageIgnore
     */
    #[Pure]
    public function getSetter(): ?ReflectionMethod
    {
        return $this->setter;
    }

    /**
     * @param ReflectionMethod|null $setter
     */
    public function setSetter(?ReflectionMethod $setter): void
    {
        $this->setter = $setter;
    }

    /**
     * @return bool 是否有 set 方法
     * @codeCoverageIgnore
     */
    #[Pure]
    public function isHasSetter(): bool
    {
        return $this->setter !== null;
    }

    /**
     * @return TypeDescription|null
     */
    #[Pure]
    public function getSetterTypeDescription(): ?TypeDescription
    {
        return $this->setterTypeDescription;
    }

    /**
     * @param TypeDescription|null $setterTypeDescription
     */
    public function setSetterTypeDescription(?TypeDescription $setterTypeDescription): void
    {
        $this->setterTypeDescription = $setterTypeDescription;
    }

    /**
     * @return bool
     * @codeCoverageIgnore
     */
    #[Pure]
    public function isSetterSameClass(): bool
    {
        return $this->setterSameClass;
    }

    /**
     * @param bool $setterSameClass
     */
    public function setSetterSameClass(bool $setterSameClass): void
    {
        $this->setterSameClass = $setterSameClass;
    }

}

# end of file
